package com.caac.core.web.action.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.caac.core.dm.User;
import com.caac.core.service.UserManager; 
import com.caac.core.web.action.BaseViewAction;
import com.caac.core.web.action.ViewForward;
import com.caac.core.web.form.BaseForm;
import com.caac.core.web.view.UserView;

import org.apache.struts.action.ActionMapping;


public class ViewUserAction extends BaseViewAction {

    private static final String VIEW_NAME = "userView";

    public ViewForward doViewExecute(ActionMapping mapping,
                                     BaseForm form,
                                     HttpServletRequest request,
                                     HttpServletResponse response) throws
            Exception {
        String id = request.getParameter("id");
        UserManager manager = this.getUserManager();
        User dm = null;
        if (id == null) {
            String username = request.getParameter("username");
            dm = manager.getUserByUsername(username);
        } else {
            dm = manager.getUserById(id);
        }
        UserView dmView = new UserView();
        dmView.setUser(dm);
        return new ViewForward(this.forward(mapping), dmView,
                               getAllViewProps(VIEW_NAME), VIEW_NAME, null);
    }
}
